package com.report.word;

import com.deepoove.poi.policy.TextRenderPolicy;
import com.deepoove.poi.render.RenderContext;
import com.deepoove.poi.template.ElementTemplate;

public class CustomTextRenderPolicy extends TextRenderPolicy {

    @Override
    protected boolean validate(Object data) {
        return true;
    }

    @Override
    public void doRender(RenderContext<Object> context) throws Exception {
        Object data = context.getData();
        if (data == null)
            data = "";
        Helper.renderTextRun(context.getRun(), data);
    }

    private boolean isDefineTemplate(ElementTemplate template) {
        String tag = template.getTagName();
        return tag.matches("^_\\.def\\(.+\\)$");
    }

    @Override
    protected void afterRender(RenderContext<Object> context) {
        super.afterRender(context);
        if (isDefineTemplate(context.getEleTemplate()))
            clearPlaceholder(context, true);
    }

}
